<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="auto">
      <el-row :gutter="24">
        <el-col :md="6" :sm="12">
          <el-form-item label="订单号" prop="ordernum">
            <el-input
                v-model="queryParams.ordernum"
                placeholder="请输入订单号"
                clearable
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12">
          <el-form-item label="下单时间">
            <el-date-picker
                v-model="dateRange"
                style="width:182px"
                value-format="yyyy-MM-dd"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12">
          <el-form-item label="车牌号" prop="carnum">
            <el-input
                v-model="queryParams.carnum"
                placeholder="请输入车牌号"
                clearable
                style="width: 140px;"
                @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :md="6" :sm="12">
          <el-form-item style="margin-bottom: 20px">
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <a style="margin-left: 8px" @click="toggleAdvanced">
              {{ advanced ? '收起' : '展开' }}
              <el-icon :class="advanced?'el-icon-arrow-up':'el-icon-arrow-down'"/>
            </a></el-form-item>
        </el-col>
        <el-collapse-transition>
          <div v-if="advanced">
            <el-col :md="6" :sm="12">
              <el-form-item label="服务类型" prop="type">
                <el-select v-model="queryParams.orderType" style="width: 150px;" placeholder="请选择订单类型" clearable>
                  <el-option
                    v-for="dict in dict.type.order_servicetype"
                    :key="dict.value"
                    :label="dict.label"
                    :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="12">
              <el-form-item label="车辆名称" prop="carname">
                <el-input
                    v-model="queryParams.carname"
                    placeholder="请输入车辆名称"
                    clearable
                    @keyup.enter.native="handleQuery"
                />
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="12">
              <el-form-item label="配送方式" prop="gettype">
                <el-select v-model="queryParams.gettype" style="width: 150px;" placeholder="请选择取车方式" clearable>
                  <el-option
                      v-for="dict in dict.type.order_gettype"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>

            <el-col :md="6" :sm="12">
              <el-form-item label="订单状态" prop="status">
                <el-select v-model="queryParams.status" style="width: 140px;" placeholder="请选择订单状态" clearable>
                  <el-option
                      v-for="dict in dict.type.vehicle_order_status"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                  />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="12">
              <el-form-item label="用户ID" prop="uid">
                <el-input
                    v-model="queryParams.uid"
                    placeholder="请输入用户ID"
                    clearable
                    @keyup.enter.native="handleQuery"
                    style="width: 130px;"/>
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="12">
              <el-form-item label="取车姓名" prop="username">
                <el-input
                    v-model="queryParams.username"
                    placeholder="请输入取车姓名"
                    clearable
                    style="width: 140px;"
                    @keyup.enter.native="handleQuery"
                />
              </el-form-item>
            </el-col>
            <el-col :md="6" :sm="12">
              <el-form-item label="取车电话" prop="tel">
                <el-input
                    v-model="queryParams.tel"
                    placeholder="请输入取车电话"
                    clearable
                    style="width: 140px;"
                    @keyup.enter.native="handleQuery"
                />
              </el-form-item>
            </el-col>
          </div>
        </el-collapse-transition>

      </el-row>


    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
            type="primary"
            plain
            icon="el-icon-plus"
            size="mini"
            @click="handleAdd"
            v-hasPermi="['merchant:vhiceodr:add']"
        >新增
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
            type="warning"
            plain
            icon="el-icon-download"
            size="mini"
            @click="handleExport"
            v-hasPermi="['merchant:vhiceodr:export']"
        >导出客户租车信息
        </el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="vehorderList" @selection-change="handleSelectionChange"
              @expand-change="load"
              ref="vehorderList">
      <el-table-column type="selection" width="50" align="center"/>
      <!--      <el-table-column label="主键id" align="center" prop="id" />
            <el-table-column label="车辆id" align="center" prop="cid" />-->
      <el-table-column type="expand">
        <template v-slot:default="scope">
          <el-timeline v-loading="scope.row.loading">
            <el-timeline-item
              v-for="(activity, index) in scope.row.children"
              :key="index"
              :timestamp="activity.createTime">
              <div>
                <span class="label-operation">
                  <dict-tag :options="dict.type.vhiceodr_status" :value="activity.markFlag"></dict-tag>
                  <!--                  {{ getLabel(activity.markFlag, 'vhiceodr_status') }}-->
                </span>
              </div>
              <div>
                <span v-if="activity.userName&&activity.userName!=''">
                操作人：{{ activity.userName }}
              </span>
                <span v-if="activity.phonenumber&&activity.phonenumber!=''">
                手机号：{{ activity.phonenumber }}
              </span>
              </div>
              <div v-if="activity.remark">
                备注：{{ activity.remark }}
              </div>
            </el-timeline-item>
          </el-timeline>
        </template>
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="orderNum" width="200"/>
      <el-table-column label="下单时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆天单价" align="center" prop="money" width="90">
        <template slot-scope="scope">
          <span>￥{{ scope.row.money }}/天</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆租金" align="center" prop="totalMoney" width="80">
        <template slot-scope="scope">
          <span>￥{{ scope.row.totalMoney }}</span>
        </template>
      </el-table-column>
      <el-table-column label="车辆押金" align="center" prop="depositMoney" width="80">
        <template slot-scope="scope">
          <span>￥{{ scope.row.depositMoney }}</span>
        </template>
      </el-table-column>
      <el-table-column label="服务类型" align="center" prop="type" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.order_servicetype" :value="scope.row.orderType"/>
        </template>
      </el-table-column>
      <el-table-column label="门店名称" align="center" prop="shopName" width="110"/>
      <el-table-column label="车牌号" align="center" prop="carNum" width="90"/>
      <el-table-column label="车辆名称" align="center" prop="carname" width="80"/>
      <el-table-column label="取车时间" align="center" prop="startTime" width="100"/>
      <el-table-column label="还车时间" align="center" prop="endTime" width="100"/>
      <el-table-column label="总天数" align="center" prop="day" width="60"/>
      <!--      <el-table-column label="${comment}" align="center" prop="uniacid" />-->
      <el-table-column label="当前接单人ID" align="center" prop="uid" width="60"/>
      <el-table-column label="支付金额" align="center" prop="prepayMoney"/>
      <el-table-column label="取车姓名" align="center" prop="username" width="75"/>
      <el-table-column label="取车电话" align="center" prop="tel" width="110"/>
      <el-table-column label="支付方式" align="center" prop="payType" width="80">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.vehicle_order_paytype" :value="scope.row.payType"/>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status" width="75">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.vhiceodr_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center"
                       class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <!--          <span v-if="scope.row.status == 1 || scope.row.status == 2 || scope.row.status == 6">-->
          <!--          <el-button-->
          <!--            type="text"-->
          <!--              plain-->
          <!--              icon="el-icon-edit"-->
          <!--              size="mini"-->
          <!--              @click="cancelOrder(scope.row)"-->
          <!--            v-hasPermi="['merchant:vhiceodr:edit']"-->
          <!--          >取消订单</el-button>-->
          <!--          </span>-->
          <el-button
            type="text"
            icon="el-icon-edit"
            size="mini"
            @click="viewOrderDetail(scope.row)"
          >详情
          </el-button>
          <el-button
            type="text"
            icon="el-icon-s-finance"
            size="mini"
            @click="updatePrepayMoney(scope.row)"
            v-hasPermi="['merchant:vhiceodr:edit']"
          >修改金额
          </el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">更多</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="assignOrder" icon="el-icon-thumb"
                                v-hasPermi="['merchant:vhiceodr:edit']">订单指派
              </el-dropdown-item>
              <el-dropdown-item command="cancelOrder" icon="el-icon-document-remove"
                                v-if="scope.row.status == 1 || scope.row.status == 2 || scope.row.status == 6"
                                v-hasPermi="['merchant:vhiceodr:edit']">取消订单
              </el-dropdown-item>
              <el-dropdown-item command="handleDelete" icon="el-icon-delete"
                                v-if="scope.row.status == 1 || scope.row.status == 2 || scope.row.status == 6"
                                v-hasPermi="['merchant:vhiceodr:remove']">删除
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

    <!--修改支付金额对话框-->
    <el-dialog :title="title" :visible.sync="payOpen" width="500px" append-to-body>
      <el-form ref="payForm" :model="payForm" :rules="payrules" label-width="80px">

        <el-form-item label="支付金额" prop="prepayMoney">
          <el-input v-model="payForm.prepayMoney" placeholder="请输入支付金额"/>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitPayForm">确 定</el-button>
        <el-button @click="cancelPayForm">取 消</el-button>
      </div>
    </el-dialog>
    <!--确认退款对话框-->
    <el-dialog :title="title" :visible.sync="refundOpen" width="500px" append-to-body>
      <el-form ref="refundForm" :model="refundForm" :rules="refundrules" label-width="80px">

        <el-form-item label="退款金额" prop="refundMoney">
          <el-input v-model="refundForm.refundMoney" placeholder="请输入退款金额"/>
        </el-form-item>
        <el-form-item label="备注" prop="refundRemark">
          <el-input v-model="refundForm.refundRemark" type="textarea" placeholder="请输入备注"
                    :autosize="{minRows: 3, maxRows: 6}" :style="{width: '100%'}"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitRefundForm">确 定</el-button>
        <el-button @click="cancelRefundForm">取 消</el-button>
      </div>
    </el-dialog>
    <!--查看订单详情-->
    <el-dialog :title="title" :visible.sync="detailOpen" width="500px" append-to-body>
      <el-form ref="detailForm" :model="detailForm" label-width="130px">

        <el-form-item label="驾驶员" prop="driverName">
          <el-input v-model="detailForm.driverName" :readonly="true"/>
        </el-form-item>
        <el-form-item label="手机号码" prop="driverPhone">
          <el-input v-model="detailForm.driverPhone" :readonly="true"/>
        </el-form-item>
        <el-form-item label="身份证号" prop="driverIdCard">
          <el-input v-model="detailForm.driverIdCard" :readonly="true"/>
        </el-form-item>
        <el-form-item label="客户手机号" prop="utelphone">
          <el-input v-model="detailForm.utelphone" :readonly="true"/>
        </el-form-item>
        <span v-if="detailForm.orderCategorize==null">
        <el-form-item label="用户ID" prop="uid">
          <el-input v-model="detailForm.uid" :readonly="true"/>
        </el-form-item>
        </span>
        <el-form-item label="订单编号" prop="ordernum">
          <el-input v-model="detailForm.ordernum" :readonly="true"/>
        </el-form-item>
        <el-form-item label="车牌号" prop="carnum">
          <el-input v-model="detailForm.carnum" :readonly="true"/>
        </el-form-item>
        <el-form-item label="车辆名称" prop="carname">
          <el-input v-model="detailForm.carname" :readonly="true"/>
        </el-form-item>
        <el-form-item label="订单类型" prop="type">
          <el-radio-group v-model="detailForm.orderType" :disabled="true">
            <el-radio
                v-for="dict in dict.type.order_type"
                :key="dict.value"
                :label="parseInt(dict.value)"
            >{{ dict.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="取车时间" prop="startTime">
          <el-input v-model="detailForm.startTime" :readonly="true"/>
        </el-form-item>
        <el-form-item label="还车时间" prop="endTime">
          <el-input v-model="detailForm.endTime" :readonly="true"/>
        </el-form-item>
        <el-form-item label="总天数" prop="day">
          <el-input v-model="detailForm.day" :readonly="true"/>
        </el-form-item>
        <el-form-item label="订单状态" prop="status">
          <el-select v-model="detailForm.status" placeholder="请选择订单状态" :disabled="true">
            <el-option
                v-for="dict in dict.type.vehicle_order_status"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车辆天单价" prop="money">
          <el-input v-model="formatMoneyValue" :readonly="true"/>
        </el-form-item>
        <span v-if="detailForm.orderCategorize==null">
        <el-form-item label="支付金额" prop="prepayMoney">
          <el-input v-model="formatPrepayMoneyValue" :readonly="true"/>
        </el-form-item>
        </span>
        <el-form-item label="是否支付" prop="ispay">
          <el-select v-model="detailForm.ispay" :disabled="true">
            <el-option
                v-for="dict in dict.type.order_ispay"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否退车辆押金" prop="isReturnVehDeposit">
          <el-select v-model="detailForm.isReturnVehDeposit" :disabled="true">
            <el-option
                v-for="dict in dict.type.order_is_return_vehdeposit"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否退违章押金" prop="isReturnVioDeposit">
          <el-select v-model="detailForm.isReturnVioDeposit" :disabled="true">
            <el-option
                v-for="dict in dict.type.order_is_return_viodeposit"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付时间" prop="paytime">
          <el-input v-model="detailForm.paytime" :readonly="true"/>
        </el-form-item>
        <el-form-item label="取车姓名" prop="username">
          <el-input v-model="detailForm.username" :readonly="true"/>
        </el-form-item>
        <el-form-item label="取车电话" prop="tel">
          <el-input v-model="detailForm.tel" :readonly="true"/>
        </el-form-item>
        <span v-if="detailForm.orderCategorize==null">
        <el-form-item label="取车地址" prop="pickUpAddress">
          <el-input v-model="detailForm.pickUpAddress" :readonly="true"/>
        </el-form-item>
        <el-form-item label="还车地址" prop="returnAddress">
          <el-input v-model="detailForm.returnAddress" :readonly="true"/>
        </el-form-item>
        </span>
        <el-form-item label="是否删除" prop="display">
          <el-select v-model="detailForm.display" :disabled="true">
            <el-option
                v-for="dict in dict.type.order_display"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="支付类型" prop="payType">
          <el-select v-model="detailForm.payType" :disabled="true">
            <el-option
                v-for="dict in dict.type.vehicle_order_paytype"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="车辆押金" prop="depositMoney">
          <el-input v-model="formatDepositMoneyValue" :readonly="true"/>
        </el-form-item>

        <el-form-item label="违章押金" prop="voainDeposit">
          <el-input v-model="formatViolationDepositValue" :readonly="true"/>
        </el-form-item>
        <span v-if="detailForm.orderCategorize==null">
        <el-form-item label="个人提成费用" prop="personComExpen">
          <el-input v-model="detailForm.personComExpen" :readonly="true"/>
        </el-form-item>

        <el-form-item label="附加费用" prop="additionalFees">
          <el-input v-model="detailForm.additionalFees" :readonly="true"/>
        </el-form-item>

        <el-form-item label="送车员" prop="deliveryName">
          <el-input v-model="formatDeliveryValue" :readonly="true"/>
        </el-form-item>
        <el-form-item label="送车员电话" prop="snatchPersonTel">
          <el-input v-model="detailForm.snatchPersonTel" :readonly="true"/>
        </el-form-item>
        </span>
        <span v-if="detailForm.orderCategorize!=null">
        <el-form-item label="订单分类" prop="orderCategorize">
          <el-select v-model="detailForm.orderCategorize" :disabled="true">
            <el-option
                v-for="dict in dict.type.order_categorize"
                :key="dict.value"
                :label="dict.label"
                :value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用车单位" prop="usingUnitName">
          <el-input v-model="detailForm.usingUnitName" :readonly="true"/>
        </el-form-item>
        <el-form-item label="行程" prop="hodmeterRemark">
          <el-input v-model="detailForm.hodmeterRemark" :readonly="true"/>
        </el-form-item>
        </span>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="detailForm.remark" type="textarea"
                    :autosize="{minRows: 3, maxRows: 6}" :style="{width: '100%'}" :readonly="true"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelViewOrder">取 消</el-button>
      </div>
    </el-dialog>
    <!--    <audio ref="audioPlayer" autoplay src="@/assets/orderaudio.mp3" crossorigin="anonymous" controls="controls" preload="auto"></audio>-->

    <update-order ref="updateOrder" @update="getList" :dict="dict"></update-order>
  </div>
</template>

<script>

import updateOrder from "@/views/order/computed/updateOrder.vue";
import {getOeaiRcrList, getVhiceodr, listVhiceodr} from "@/api/merchant/order";

export default {
  name: "Vehorder",
  components: {
    updateOrder
  },
  dicts: ['order_isuse', 'order_membertype', 'order_ispay', 'order_istui', 'wehicle_iszx', 'order_open_zx_service', 'order_active', 'order_ispl', 'order_gettype','vehicle_source',
    'order_display', 'order_type', 'vehicle_order_status', 'vehicle_order_paytype', 'order_is_return_vehdeposit', 'order_is_return_viodeposit', 'order_source', 'order_categorize', 'order_servicetype', 'vehicle_order_paytype', 'vhiceodr_status'],
  data() {
    return {
      // 搜索条件展开
      advanced: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      //isRecords: false,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 订单语音提醒开关
      audioEnabled: false,
      // 日期范围
      dateRange: [],
      // 总条数
      total: 0,
      // 租车订单表格数据
      vehorderList: [{
        id: 1,
        hasChildren: true,
        ordernum: '1234567',
        money: '45',
        shopName: '测试',
        carnum: '湘A54132',
        day: '4',
        children: []
      }],
      // 门店选项
      branchOptions: [],
      goodsList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      payOpen: false,
      refundOpen: false,
      detailOpen: false,
      // 门店查询参数
      queryBranchParams: {
        uniacid: null
      },
      queryOrderParams: {
        startShop: null,
        status: null
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cid: null,
        carnum: null,
        carname: null,
        gettype: null,
        orderType: null,
        typeid: null,
        startTime: null,
        endTime: null,
        startShop: null,
        endShop: null,
        day: null,
        uniacid: null,
        uid: null,
        createtime: null,
        status: null,
        membertype: null,
        delay: null,
        integralMoney: null,
        integral: null,
        money: null,
        totalMoney: null,
        prepayMoney: null,
        fee: null,
        serviceFee: null,
        zxServiceFee: null,
        openZxService: null,
        couponMoney: null,
        coupon: null,
        ispay: null,
        istui: null,
        paytime: null,
        isuse: null,
        usetime: null,
        outTradeNo: null,
        outRefundNo: null,
        transid: null,
        ordernum: null,
        username: null,
        tel: null,
        prepayId: null,
        active: null,
        display: null,
        returnTime: null,
        ispl: null,
        xzday: null,
        xzmoney: null,
        xztime: null,
        driveid: null,
        iszx: null,
        isdeposit: null,
        depositMoney: null,
        parentId1: null,
        parentId2: null,
        parentId3: null
      },
      // 表单参数
      form: {},
      payForm: {},
      refundForm: {},
      detailForm: {},
      goodsForm: {},
      // 表单校验
      rules: {
        orderCategorize: [
          {required: true, message: "请选择订单分类", trigger: "blur"}
        ],
        cid: [
          {required: true, message: "车牌号不能为空", trigger: "blur"}
        ],
        carname: [
          {required: true, message: "车辆名称不能为空", trigger: "blur"}
        ],
        utelphone: [
          {required: true, message: "客户手机号不能为空", trigger: "blur"}
        ],
        gettype: [
          {required: true, message: "请选择取车方式", trigger: "blur"}
        ],
        startTime: [
          {required: true, message: "请选择取车时间", trigger: "blur"}
        ],
        endTime: [
          {required: true, message: "请选择还车时间", trigger: "blur"}
        ],
        startShop: [
          {required: true, message: "请选择取车门店", trigger: "blur"}
        ],
        day: [
          {required: true, message: "总天数不能为空", trigger: "blur"}
        ],
        money: [
          {required: true, message: "车辆天单价不能为空", trigger: "blur"}
        ],
        totalMoney: [
          {required: true, message: "总价不能为空", trigger: "blur"}
        ],
        prepayMoney: [
          {required: true, message: "支付金额不能为空", trigger: "blur"}
        ]
      },
      // 修改支付金额表单校验
      payrules: {
        prepayMoney: [
          {required: true, message: "请输入支付金额", trigger: "blur"}
        ]
      },
      // 退款金额表单校验
      refundrules: {
        refundMoney: [
          {required: true, message: "请输入退款金额", trigger: "blur"}
        ]
      }
    };
  },
  created() {
    this.getList();

  },
  computed: {
    formatMoneyValue() {
      return '￥' + this.detailForm.money + '/天';
    },
    formatTotalMoneyValue() {
      return '￥' + this.detailForm.totalMoney;
    },
    formatVehComAmountValue() {
      if (this.detailForm.vehComAmount != null) {
        return '￥' + this.detailForm.vehComAmount;
      } else {
        return '';
      }
    },
    formatPrepayMoneyValue() {
      return '￥' + this.detailForm.prepayMoney;
    },
    formatRefundMoneyValue() {
      if (this.detailForm.refundMoney != null) {
        return '￥' + this.detailForm.refundMoney;
      } else {
        return '';
      }
    },
    formatDepositMoneyValue() {
      return '￥' + this.detailForm.depositMoney;
    },
    formatViolationDepositValue() {
      if (this.detailForm.voainDeposit != null) {
        return '￥' + this.detailForm.voainDeposit;
      } else {
        return '';
      }
    },
    formatDeliveryValue() {
      if (this.detailForm.snatchPersonName != null) {
        return this.detailForm.snatchPersonName;
      } else {
        return this.detailForm.deliveryName;
      }
    }
  },
  methods: {
    getLabel(dictValue, dictType) {
      for (let i = 0; i < this.dict.type[dictType].length; i++) {
        if (this.dict.type[dictType][i].value == dictValue) {
          return this.dict.type[dictType][i].label
        }
      }
    },
    toggleAdvanced() {
      this.advanced = !this.advanced
    },
    assignOrder(row) {
      this.$router.push({
        path: '/order/assignOrder',
        query: {
          orderNum: row.orderNum,
          orderId: row.id
        }
      })
    },
    handleCommand(command, row) {
      switch (command) {
        case "updateOrderStatus":
          this.updateOrderStatus(row);
          break;
        case "cancelOrder":
          this.cancelOrder(row);
          break;
        case "handleDelete":
          this.handleDelete(row)
          break
        case "handleReturnVehicle":
          this.handleReturnVehicle(row)
          break
        case "handleCompleteOrder":
          this.handleCompleteOrder(row)
          break
        case "assignOrder":
          this.assignOrder(row)
        default:
          break;
      }
    },
    load(row, expanded) {
      console.log('load', row)
      if (!row.isExpand) {
        row.loading = true
        row.isExpand = true
        let index
        for (let i = 0; i < this.vehorderList.length; i++) {
          if (this.vehorderList[i].id == row.id) {
            index = i
            break
          }
        }
        getOeaiRcrList(row.orderNum).then(res => {
          if (res.code == 200) {
            this.vehorderList[index].loading = false
            this.$set(this.vehorderList[index], 'children', res.data)
            this.$nextTick(() => {
              this.$refs.vehorderList.toggleRowExpansion(row, true)
            })
          }
        })
        // setTimeout(() => {
        //   //this.vehorderList[index]
        //   for (let i = 0; i < this.vehorderList.length; i++) {
        //     if (this.vehorderList[i].id == row.id) {
        //       this.vehorderList[i].loading = false
        //       this.$set(this.vehorderList[i], 'children', [
        //         {
        //           content: '创建订单',
        //           id: 2,
        //           ordernum: '1234567',
        //           money: '21',
        //           timestamp: '2024-07-05',
        //           shopName: '测试',
        //           carnum: '湘A54132',
        //           day: '2'
        //         },
        //         {
        //           content: '续租',
        //           id: 2,
        //           ordernum: '1234567',
        //           money: '21',
        //           timestamp: '2024-07-08',
        //           shopName: '测试',
        //           carnum: '湘A54132',
        //           day: '2'
        //         }
        //       ])
        //       break
        //     }
        //   }
        // }, 1000)
      }
    },
    getList() {
      this.loading = true
      listVhiceodr(this.queryParams).then(res => {
        this.loading = false
        if (res.code === 200) {
          this.total = res.total;
          this.vehorderList = res.rows
        }
      })
    },
    handleBlur(event) {
      this.form.totalMoney = this.form.day * this.form.money;
    },
    handleTotalBlur(event) {
      this.form.money = (this.form.totalMoney / this.form.day).toFixed(2);
    },
    handleChange(value) {
      getGoods(value).then(response => {
        this.form.carname = response.data.name;
      });
    },
    handleEndDateChange() {
      var timeDay = 0;
      //this.form.startTime为开始时间
      let today = new Date(this.form.startTime);
      //格式化为年月日时分秒
      today.setHours(0, 0, 0, 0);
      //this.form.endTime为结束时间
      if (this.form.endTime != null) {
        var timeDiff = new Date(this.form.endTime) - 0 - new Date(today) - 0
        timeDay = (timeDiff / 86400000)
      } else {
        timeDay = 0
      }
      //有效位数进行保留，取整
      this.form.day = Number(timeDay * 1).toFixed(0);

    },
    showAudio() {
      /* var userId=store.getters.userId;
       this.queryBranchParams.uniacid=userId;
       listBranch(this.queryBranchParams).then(response => {
         var branchList = response.rows;
         for(var i=0;i<branchList.length;i++){
             var branchid=branchList[i].id;
             this.queryOrderParams.startShop=branchid;
             this.queryOrderParams.status=2;
             listVehorder(this.queryOrderParams).then(response => {
                if(response.total>0){
                  this.isRecords=true;
                }
             });
         }
       });*/
      //var shopIds=store.getters.shopIds;
      //this.queryOrderParams.startShop=shopIds;
      this.queryOrderParams.statusStr = '2,7';
      listVehorder(this.queryOrderParams).then(response => {
        if (response.total > 0) {
          //this.isRecords=true;
          //if(this.isRecords){
          //如果用户有订单则进行语音提醒
          const audioPlayer = this.$refs.audioPlayer;
          audioPlayer.play();
          //}
        }
      });

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 取消支付金额修改按钮
    cancelPayForm() {
      this.payOpen = false;
    },
    // 取消退款按钮
    cancelRefundForm() {
      this.refundOpen = false;
    },
    // 取消查看订单详情按钮
    cancelViewOrder() {
      this.detailOpen = false;
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        cid: null,
        carnum: null,
        carname: null,
        gettype: null,
        type: null,
        typeid: null,
        startTime: null,
        endTime: null,
        startShop: null,
        endShop: null,
        day: null,
        uniacid: null,
        uid: null,
        createtime: null,
        status: null,
        membertype: null,
        delay: null,
        integralMoney: null,
        integral: null,
        money: null,
        totalMoney: null,
        prepayMoney: null,
        fee: null,
        serviceFee: null,
        zxServiceFee: null,
        openZxService: null,
        couponMoney: null,
        coupon: null,
        ispay: null,
        istui: null,
        paytime: null,
        isuse: null,
        usetime: null,
        outTradeNo: null,
        outRefundNo: null,
        transid: null,
        ordernum: null,
        username: null,
        tel: null,
        prepayId: null,
        active: null,
        display: null,
        returnTime: null,
        ispl: null,
        xzday: null,
        xzmoney: null,
        xztime: null,
        driveid: null,
        iszx: null,
        isdeposit: null,
        depositMoney: null,
        parentId1: null,
        parentId2: null,
        parentId3: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      // this.reset();
      // this.open = true;
      // this.title = "添加租车订单";
      this.$refs.updateOrder.openUpdateOrder()
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const id = row.id || this.ids
      this.$refs.updateOrder.openUpdateOrder(row)

    },
    /** 查看订单详情 */
    viewOrderDetail(row) {
      const orderNum = row.orderNum || this.orderNum
      getVhiceodr(orderNum).then(response => {
        this.detailForm = response.data;
        this.detailOpen = true;
        this.title = "订单详情";
      })
    },
    /** 修改支付金额 */
    updatePrepayMoney(row) {
      const id = row.id || this.ids
    },
    /** 取消订单操作 */
    cancelOrder(row) {
      const id = row.id || this.ids
    },
    /** 改为待送车操作 */
    updateOrderStatus(row) {
      const id = row.id || this.ids
    },
    /** 确认还车操作 */
    handleReturnVehicle(row) {
      const id = row.id || this.ids

    },
    /** 确认完成订单操作 */
    handleCompleteOrder(row) {
      const id = row.id || this.ids
    },


    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {

          } else {

          }
        }
      });
    },
    /** 修改支付金额提交按钮 */
    submitPayForm() {
      this.$refs["payForm"].validate(valid => {
        if (valid) {
          if (this.payForm.id != null) {
          }
        }
      });
    },
    /** 确认退款提交按钮 */
    submitRefundForm() {
      this.$refs["refundForm"].validate(valid => {
        if (valid) {
          if (this.refundForm.id != null) {
            this.refundForm.status = 0;//订单状态改为已完成
            this.refundForm.istui = 1;//是否退款改为已退款

          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      /*this.$modal.confirm('是否确认删除订单编号为"' + row.ordernum + '"的数据项？').then(function() {
        return delVehorder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});*/
      this.$modal.confirm('是否确认删除订单编号为"' + row.ordernum + '"的数据项？').then(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('merchant/vhiceodr/export', {
        ...this.queryParams
      }, `vehorder_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
<style>
.label-operation {
  color: #00afff
}
</style>
